package test.cumulativeProtocol.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import test.cumulativeProtocol.codec.TProtocolCodecFactory;

import com.mahjong.server.common.Common;

public class TServer {

  public static void main(String[] args) {
    NioSocketAcceptor acceptor=new NioSocketAcceptor();
    DefaultIoFilterChainBuilder filterChain=acceptor.getFilterChain();// 过滤链
    filterChain.addLast("serverFilter", new ProtocolCodecFilter(new TProtocolCodecFactory(Charset.forName("utf-8"))));// 添加filter
    acceptor.setHandler(new TServerHandler());// handler
    acceptor.getSessionConfig().setReadBufferSize(1024 * 1);// 1K
    acceptor.getSessionConfig().setSendBufferSize(1024 * 1);// 1K
    try {
      acceptor.bind(new InetSocketAddress(Common.PORT));
    } catch(IOException e) {
      e.printStackTrace();
    }
    System.out.println("MinaServer started @ " + Common.PORT);
  }
}
